﻿//-----------------------------------------------------------------
// 创建时间:  2008年11月10日
// 创建者  : WuGui.Yang
//-----------------------------------------------------------------
using System; 
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.Transactions;

namespace Ruandao.Foundation.DataAccess
{
    using Ruandao.MiniDac;
	/// <summary>
	/// Table [TagGroup] MiniDac Entity Class 
	/// </summary>
	public partial class TagGroupEntity : EntityBase< TagGroupEntity >
	{

        static public IList<TagGroupEntity> SearchAllEntities()
        {
            return SearchByCondition("");
        }

        static public IList<TagGroupEntity> SearchEntities(int tagGroupId)
        {
            string condition = "WHERE TagGroupId=" + tagGroupId.ToString();
            return SearchByCondition( condition );
        }

        // TagContentIndex表中的内容通过级联删除自动删除。
        static public void DestroyGroup(int tagGroupId)
        {
            string sql1 = "DELETE FROM TagCategory WHERE TagGroupId=" + tagGroupId.ToString();
            string sql2 = "DELETE FROM TagIndex    WHERE TagGroupId=" + tagGroupId.ToString();
            string sql3 = "DELETE FROM ContentTags WHERE TagGroupId=" + tagGroupId.ToString();
            string sql4 = "DELETE FROM Tag         WHERE TagGroupId=" + tagGroupId.ToString();
            string sql5 = "DELETE FROM TagGroup    WHERE TagGroupId=" + tagGroupId.ToString();

            using (TransactionScope ts = new TransactionScope())
            {
                ExecuteNonQuery(sql1);
                ExecuteNonQuery(sql2);
                ExecuteNonQuery(sql3);
                ExecuteNonQuery(sql4);
                ExecuteNonQuery(sql5);
                ts.Complete();
            }
        }
	}

}
